package com.senseuni.da.ui.views

import android.content.Context
import android.util.AttributeSet
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import com.senseuni.da.R

class MainMenuView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0,
    defStyleRes: Int = 0
) : FrameLayout(context, attrs, defStyleAttr, defStyleRes) {

    private val iconImageView: ImageView
    private val titleLabel: TextView

    init {
        inflate(context, R.layout.layout_main_menu_item, this)

        iconImageView = findViewById(R.id.imageView)
        titleLabel = findViewById(R.id.textView)

        val typedArray = context.obtainStyledAttributes(attrs, R.styleable.MainMenuView, defStyleAttr, defStyleRes)
        val iconResId = typedArray.getResourceId(R.styleable.MainMenuView_mnvIcon, R.mipmap.ic_main_menu_gallery)
        val titleText = typedArray.getString(R.styleable.MainMenuView_mnvText) ?: ""

        iconImageView.setImageResource(iconResId)
        titleLabel.text = titleText

        typedArray.recycle()
    }

    fun setIconResource(resId: Int) {
        iconImageView.setImageResource(resId)
    }

    fun setTitle(text: String) {
        titleLabel.text = text
    }

}
